import { GetListByPage } from '@/axios/api/FreezeMoneyAPI'

const freezemoney = {
    namespaced: true,
    state: () => ({  
        tabledata: [],
        showmodal: false,
        title: '',
        creatrouter: '',
        editrouter: '',
        fullscreen: true,
        tablecolumns: [],
        currentFreezeMoneyID: '',
        total: 0,
        pageIndex: 1,
        pageSize: 15,
        pageSizeOpts: [15,25,50,100]
    }),
    mutations: { 
        UPDATE_TABLE_COLUMNS: (state,payload) => {
            //console.log(payload)
            payload = [
                {
                    type: 'selection',
                    width: 60,
                    fixed:'left',
                    align: 'center'
                },
                {
                    type: 'index',
                    key: 'Index',
                    title: '序号',
                    width: 80,
                    fixed:'left',
                    align: 'center'
                },
                {
                    title: '冻结银行',
                    key: 'BankName',
                    align:'center',
                    minWidth: 300,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.BankName)
                    }
                },
                {
                    title: '冻结账户',
                    key: 'Account',
                    align:'center',
                    minWidth: 265,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Account)
                    }
                    /* filters: [
                        {
                            label: 'Greater than 4000',
                            value: 1
                        },
                        {
                            label: 'Less than 4000',
                            value: 2
                        }
                    ],
                    filterMultiple: false,
                    filterMethod (value, row) {
                        if (value === 1) {
                            return row.show > 4000;
                        } else if (value === 2) {
                            return row.show < 4000;
                        }
                    } */
                },
                {
                    title: '账户尾号',
                    key: 'AccountTail',
                    align:'center',
                    minWidth: 100,
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.AccountTail)
                    }
                    /* filters: [
                        {
                            label: 'Greater than 4000',
                            value: 1
                        },
                        {
                            label: 'Less than 4000',
                            value: 2
                        }
                    ],
                    filterMultiple: false,
                    filterMethod (value, row) {
                        if (value === 1) {
                            return row.show > 4000;
                        } else if (value === 2) {
                            return row.show < 4000;
                        }
                    } */
                },
                {
                    title: '涉案项目',
                    key: 'Project',
                    align:'center',
                    minWidth: 300,
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Project)
                    }
                },
                {
                    title: '冻结金额',
                    key: 'Amount',
                    align:'center',
                    minWidth: 150,
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Amount)
                    }
                },
                {
                    title: '应确认利息',
                    key: 'FreezeInterest',
                    align:'center',
                    minWidth: 150,
                    fixed:'left',
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.FreezeInterest)
                    }
                },
                {
                    title: '冻结确认',
                    key: 'FreezeConfirm',
                    align:'center',
                    minWidth: 100,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"center" }},params.row.FreezeConfirm ? "已确认" : "待确认")
                    }
                },
                {
                    title: '诉讼案号',
                    key: 'CaseCode',
                    align:'center',
                    minWidth: 200,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.CaseCode)
                    }
                },
                {
                    title: '案件阶段',
                    key: 'CaseStatus',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.CaseStatus)
                    }
                },
                {
                    title: '判决结果',
                    key: 'JudgeResult',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.JudgeResult)
                    }
                },
                {
                    title: '项目经理',
                    key: 'ProjectManager',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.ProjectManager)
                    }
                },
                {
                    title: '上诉原告',
                    key: 'Plaintiff',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Plaintiff)
                    }
                },
                {
                    title: '冻结时间',
                    key: 'FreezeTime',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }}, params.row.FreezeTime)
                    }
                },
                {
                    title: '解冻时间',
                    key: 'UnFreezeTime',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.UnFreezeTime)
                    }
                },
                {
                    title: '冻结期限（天）',
                    key: 'FreezeDayCount',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.FreezeDayCount)
                    }
                },
                {
                    title: '利率',
                    key: 'FreezeRateShow',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.FreezeRateShow)
                    }
                },
                {
                    title: '备注',
                    key: 'Remark',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Remark)
                    }
                },
                {
                    title: '分管项目财务',
                    key: 'Accountant',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.Accountant)
                    }
                },
                {
                    title: '冻结落实人',
                    key: 'FreezeOperator',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.FreezeOperator)
                    }
                },
                {
                    title: '借条',
                    key: 'FlowBalance',
                    align:'center',
                    minWidth: 150,
                    render:(h,params)=>{
                        return h('div',{style: { textAlign:"left" }},params.row.FlowBalance)
                    }
                }
            ]
            state.tablecolumns = payload;
        },
        UPDATE_TABLE_DATA: (state,payload) => {
            //console.log(payload)
            /* payload = [
                {
                    Guid: '17gd-djgk-gdkgj-gdkf12-dfg',
                    FreezeMoneyName: '交行诸暨支行',
                    FreezeMoneyAccount: '1211024409059906581',
                    AccountTail: '6581',
                    AccountType: '一般户',
                    BeginBalance: 0.00,
                    EndingBalance: 0.00,
                    FreezeMoney: 0.00,
                    FlowBalance: 0.00
                }
            ]; */
            state.total = payload.totalCount;
            state.tabledata = payload.items;
        },
        CHANGE_TITLE: (state,payload) => {
            state.title = payload;
        },
        CHANGE_MODAL: (state) => {
            state.showmodal = !state.showmodal;
        },
        SETTING_ID: (state,payload) => {
            state.currentFreezeMoneyID= payload;
        },
        SETTING_PAGEINDEX: (state,payload) => {
            state.pageIndex = payload;
        },
        SETTING_PAGESIZE: (state,payload) => {
            state.pageSize = payload;
        },
        SETTING_CREATROUTER: (state,payload) => {
            state.creatrouter = payload;
        },
        SETTING_EDITROUTER: (state,payload) => {
            state.editrouter = payload;
        },
        CREATE: (state,payload) => {
            state.tabledata.push(payload)
        },
        UPDATE:(state,payload) => {
            let index = state.tabledata.findIndex(item => item.AccountGuid === payload.Guid);
            state.tabledata.splice(index,1,payload)
        }
    },
    actions: {
        InitFreezeMoney({commit},payload){

            commit('SETTING_CREATROUTER',payload.CreatRouter)

            commit('SETTING_EDITROUTER',payload.EditRouter)

            GetListByPage({pageIndex: payload.PageIndex,pageSize: payload.PageSize}).then(res =>{
                commit('UPDATE_TABLE_DATA',res); 
            });

            commit('UPDATE_TABLE_COLUMNS',payload.TableColumns);

        },
        ChangePageIndex({commit},payload){

            commit('SETTING_PAGEINDEX',payload.PageIndex);
            
            GetListByPage({pageIndex: payload.PageIndex,pageSize: payload.PageSize,keyword: payload.Keyword}).then(res =>{
                commit('UPDATE_TABLE_DATA',res); 
            });

        },
        ChangePageSize({commit},payload){
            commit('SETTING_PAGESIZE',payload.PageSize);
            GetListByPage({pageIndex: payload.PageIndex,pageSize: payload.PageSize,keyword: payload.Keyword}).then(res =>{
                commit('UPDATE_TABLE_DATA',res); 
            });
        },
        UpdateTableAsync({commit},payload){
            /* setTimeout(() => {
                
            }, 1000) */
            GetListByPage({pageIndex: payload.PageIndex,pageSize: payload.PageSize,keyword: payload.Keyword}).then(res =>{
                commit('UPDATE_TABLE_DATA',res); 
            });
        },
        CreateView({commit}){
            commit('CHANGE_TITLE',"创建冻结信息")
            commit('CHANGE_MODAL');
            commit('SETTING_ID','');
            
        },
        UpdateView({commit},payload){
            commit('CHANGE_TITLE',"编辑冻结信息")
            commit('CHANGE_MODAL');
            commit('SETTING_ID',payload);
        },
        Cancel({commit}){
            commit('CHANGE_MODAL');
        }
    },
    getters: { 
        tablecolumns: state => { state.tablecolumns },
        tabledata: state => state.tabledata,
        showmodal: state => state.showmodal,
        pageIndex: state => { state.pageIndex },
        pageSize: state => state.pageSize
        /* creatrouter: state => state.creatrouter,
        editrouter: state => state.editrouter */
    }
}

export default freezemoney